<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../font/iconfont.css">
    <title>Document</title>
</head>

<body>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        .woman {
            width: 640px;
            height: 360px;
            margin: 50px auto;
            position: relative;
            width: 640px;
            background-image: url("../images/1.jpg");
            background-size: cover;

        }


        .woman .left {
            height: 30px;
            width: 30px;
            position: absolute;
            color: #fff;
            font-size: 30px;
            top: 50%;
            transform: translate(0, -50%);
            left: 0;
        }

        .woman .right {
            height: 30px;
            width: 30px;
            position: absolute;
            color: #fff;
            font-size: 30px;
            top: 50%;
            transform: translate(0, -50%);
            right: 0px;

        }

        .woman .active {
            background-color: rgba(255, 255, 255, 0.5);
        }

        .woman .dat {
            position: absolute;
            display: flex;
            list-style: none;
            bottom: 20px;
            left: 20px;

        }

        .woman .dat li {
            width: 22px;
            height: 22px;
            padding: 4px;
            /* background-color: pink; */
            margin-left: 5px;
            border-radius: 50%;
        }

        .woman .dat li::after {
            content: "";
            display: block;
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background-color: #fff;
        }
    </style>
    <div class="woman">
        <div class="left iconfont icon-back"></div>
        <div class="right iconfont icon-right1"></div>
        <ol class="dat">
            <li class="active" data-id="0"></li>
            <li data-id="1"></li>
            <li data-id="2"></li>
            <li data-id="3"></li>
            <li data-id="4"></li>
            <li data-id="5"></li>
            <li data-id="6"></li>
            <li data-id="7"></li>
            <li data-id="8"></li>
            <li data-id="9"></li>
        </ol>
    </div>

    <script>
        let i = 0
        const next = document.querySelector(".woman .right")
        const prve = document.querySelector(".woman .left")
        const backimg = document.querySelector(".woman")
        const imgArry = [
            { url: '../images/1.jpg' },
            { url: '../images/2.jpg' },
            { url: '../images/3.jpg' },
            { url: '../images/4.jpg' },
            { url: '../images/5.jpg' },
            { url: '../images/6.jpg' },
            { url: '../images/7.jpg' },
            { url: '../images/8.jpg' },
            { url: '../images/9.jpg' },
            { url: '../images/10.jpg' },

        ]
        function rightFun() {
            // console.log("11111")    
            i++
            toggle()
        }
        function leftFun() {
            i--
            toggle()
        }

        function toggle() {
            i = (i + imgArry.length) % imgArry.length
            backimg.style.backgroundImage = `url(${imgArry[i].url})`

            document.querySelector(".woman .active").classList.remove("active")
            const li = document.querySelector(`.woman .dat li:nth-child(${i + 1})`)
            li.classList.add("active")
        }
        let timerId = setInterval(function () { next.click() }, 1000)
        next.addEventListener('click', rightFun)
        prve.addEventListener('click', leftFun)
        // const lis = document.querySelectorAll(".dat li")
        // console.log(lis)
        // for (let index = 0; index < lis.length; index++) {
        //     lis[index].addEventListener('click',function () {
        //         i = index
        //         toggle()
        //     })
        // }
        ol = document.querySelector(".dat")

        ol.addEventListener("click",function(e){
            // console.log(e.target.dataset.id)
            if (e.target.tagName === "LI"){
            //     document.querySelector(".dat .active").classList.remove("active")
            //     e.target.classList.add("active")
                // i = parseInt(e.target.dataset.id)
                // console.log(e.target.dataset.id);
                // console.log(e.target.tagName);
                i = parseInt(e.target.dataset.id)
                toggle()
            }

        })
        backimg.addEventListener("mouseenter", function () {
            clearInterval(timerId)
        })
        backimg.addEventListener("mouseleave", function () {
            clearInterval(timerId)
            timerId = setInterval(function () { next.click() }, 1000)
        })
        //    const ol =  document.querySelector(".woman .dat")



    </script>

</body>

</html>